<template>
  <div>
<!--  搜索  -->
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="客户姓名">
        <el-input v-model="formInline.user" placeholder="客户姓名"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="selectData">查询</el-button>
      </el-form-item>
    </el-form>
<!--  数据展示  -->
    <el-table
      :data="tableData.slice(5*(this.currentPage-1),(5*this.currentPage))"
      height="270"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="ID"
        width="300">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="300">
      </el-table-column>
      <el-table-column
        prop="age"
        label="年龄"
        width="300">
      </el-table-column>
    </el-table>
    <!--    分页-->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :pager-count="5"
      :page-size="5"
      layout="total, prev, pager, next"
      :total="this.tableData.length">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name:"selectUser",
  created() {
    this.getData()
  },
  data() {
    return {
      formInline: {
        user: '',
        age: '',
      },
      tableData: [],
      searchTableData:[],

      //分页
      currentPage:"",
    }
  },
  methods:{
    async getData() {
      var _this = this;
      await this.axios({
        method: "get",
        url: "http://192.168.1.3:8080/getData",
      }).then(function (response) {
        response.data.forEach((item) => {
          _this.tableData.push({
            id: item.id,
            name: item.name,
            age: item.age,
          })
          _this.searchTableData = _this.tableData;
        });
      });
    },
    selectData(){
      this.tableData=[];
      for(let i = 0; i<this.searchTableData.length; i++){
        if(this.searchTableData[i].name.indexOf(this.formInline.user)>=0){
          this.tableData.push(this.searchTableData[i])
        }
      }
    },

    handleSizeChange(){
    },
    handleCurrentChange(){
    },
  },
}
</script>
